home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / QuickTime VR / MacOS / QuickDraw™ 3D 1.0.6F4 SDK / Samples / SampleCode / Tumbler and Podium / Tumbler_offscreen.c < prev    next >
Encoding:
Text File  |  1995-05-31  |  5.6 KB  |  228 lines  |  [TEXT/MPS ]

  1. //
  2. //        Offscreen.c
  3. //
  4. // To Do:
  5. //
  6. // This thing calls updateGWorld each time through, this is slow, fix
  7. //
  8.  
  9. #include "QD3D.h"
  10. #include "QD3DDrawContext.h"
  11. #include "QD3DShader.h"
  12. #include "QD3DGeometry.h"
  13. #include "QD3DStyle.h"
  14. #include "QD3DTransform.h"
  15. #include "QD3DMath.h"
  16.  
  17.  
  18. #include "Tumbler_globals.h"
  19. #include "Tumbler_prototypes.h"
  20. #include "Tumbler_offscreen.h"
  21. #include "Tumbler_windows.h"
  22.  
  23.  
  24.  
  25. TQ3Status DrawOffscreen(DocumentPtr theDocument)
  26.  
  27. {
  28.  
  29.     if( theDocument->documentGroup ) {
  30.  
  31.         RgnHandle    windowRgn, growRgn, clipRgn;
  32.         Rect        growRect;
  33.         TQ3Vector3D    globalScale;
  34.         TQ3Vector3D    globalTranslate;
  35.         
  36.         globalScale.x = globalScale.y = globalScale.z = theDocument->documentGroupScale;
  37.         globalTranslate = *(TQ3Vector3D *)&theDocument->documentGroupCenter;
  38.         Q3Vector3D_Scale(&globalTranslate, -1, &globalTranslate);
  39.     
  40.         SetPort(theDocument->theWindow);
  41.     
  42.         growRect = theDocument->theWindow->portRect;
  43.         growRect.top = growRect.bottom -15;
  44.         growRect.left = growRect.right -15;
  45.  
  46.         growRgn = NewRgn();
  47.         RectRgn(growRgn, &growRect);
  48.         
  49.         windowRgn = NewRgn();
  50.         RectRgn(windowRgn, &theDocument->theWindow->portRect);
  51.         
  52.         clipRgn = NewRgn();
  53.         DiffRgn(windowRgn, growRgn, clipRgn);
  54.         
  55.         SetClip(clipRgn);
  56.         
  57.         Q3View_StartRendering(theDocument->theView);
  58.         
  59.         do {                
  60.             TQ3SubdivisionStyleData        subData = {kQ3SubdivisionMethodConstant, 20, 20};
  61.         
  62.             Q3Shader_Submit(theDocument->illuminationShader, theDocument->theView);
  63.  
  64.             if( theDocument->light == kQ3True ) {
  65.                 Q3Object_Submit(theDocument->light1, theDocument->theView);
  66.                 Q3Object_Submit(theDocument->light2, theDocument->theView);
  67.                 Q3Object_Submit(theDocument->light3, theDocument->theView);
  68.             }
  69.         
  70.             if( theDocument->shaded == kQ3True )
  71.                 Q3Style_Submit(theDocument->backfacingStyle, theDocument->theView) ;
  72.                                 
  73.             Q3InterpolationStyle_Submit(theDocument->currentInterpolation,theDocument->theView);
  74.             
  75.             Q3SubdivisionStyle_Submit( &subData,theDocument->theView);
  76.             
  77.             Q3MatrixTransform_Submit( &theDocument->modelRotation, theDocument->theView);
  78.             Q3ScaleTransform_Submit(&globalScale, theDocument->theView);
  79.             Q3TranslateTransform_Submit(&globalTranslate, theDocument->theView);
  80.                         
  81.             Q3DisplayGroup_Submit(theDocument->documentGroup, theDocument->theView);
  82.             
  83.         } while (Q3View_EndRendering(theDocument->theView) == kQ3ViewStatusRetraverse);
  84.  
  85.         ClipRect(&theDocument->theWindow->portRect);
  86.         DisposeRgn(clipRgn);
  87.         DisposeRgn(windowRgn);
  88.         DisposeRgn(growRgn);
  89.     } else {
  90.     
  91.         Rect    theRect = theDocument->theWindow->portRect;
  92.  
  93. #ifndef PODIUM_APP
  94.         // only want to color the bg for Tumbler
  95.         RGBColor color = { 0xFFFF, 0xFFFF, 0xFFFF};
  96.         
  97.         color.red *= theDocument->clearColor.r;
  98.         color.green *= theDocument->clearColor.g;
  99.         color.blue *= theDocument->clearColor.b;
  100.         
  101.         RGBBackColor(&color);
  102. #endif
  103.  
  104.         EraseRect( &theRect );
  105.         
  106. #ifndef PODIUM_APP
  107.         color.blue = color.green = color.red  =  0xFFFF;
  108.         RGBBackColor(&color);
  109. #endif
  110.  
  111.     }
  112.  
  113.     
  114.     return(kQ3Success);
  115. }
  116.  
  117.  
  118.  
  119. void DrawOnscreen(DocumentPtr theDocument)
  120. {
  121. #if 0
  122.     Rect    srcRect, dstRect;
  123.     CGrafPtr    savedPort ;
  124.     GDHandle    savedDevice ;
  125.  
  126.     if(theDocument->theOffscreen == nil || theDocument->theOffscreen->offscreenWorld == nil) {
  127.         // Draw Offscreen will allocate them
  128.         if( DrawOffscreen(theDocument) == nil)
  129.             return;
  130.     }
  131.     
  132.     srcRect = theDocument->theOffscreen->offscreenWorld->portRect;
  133.     dstRect = theDocument->theWindow->portRect;
  134.     
  135.     if(!EqualRect(&theDocument->theOffscreen->offscreenWorld->portRect, &dstRect) ) {
  136.         /* Size of the window changed */
  137.         if( DrawOffscreen(theDocument) == nil)
  138.             return;
  139.     }
  140.  
  141.     srcRect.right  -= 15;
  142.     srcRect.bottom -= 15;
  143.  
  144.     dstRect.right  -= ;
  145.     dstRect.bottom -= ;
  146.     
  147.     GetGWorld(&savedPort,&savedDevice);
  148.     SetGWorld(theDocument->theOffscreen->windowPort, theDocument->theOffscreen->windowDevice);
  149.     
  150.     CopyBits(&((GrafPtr) theDocument->theOffscreen->offscreenWorld)->portBits,
  151.              (BitMap *) &(theDocument->theOffscreen->windowPort)->portPixMap,
  152.              &srcRect, &dstRect, srcCopy, 0L);
  153.         
  154.     SetGWorld( savedPort, savedDevice);
  155. #else
  156.     TQ3DrawContextObject        drawCtx;
  157.     RgnHandle                oldClip;
  158.     Rect                    contentRect;
  159.     GrafPtr                    savedPort ;
  160.     
  161.     GetPort( &savedPort ) ;
  162.     SetPort(theDocument->theWindow);
  163.     
  164.     oldClip = NewRgn();
  165.     GetClip(oldClip);
  166.  
  167.     contentRect = theDocument->theWindow->portRect;
  168. //    contentRect.bottom -= 15;
  169. //    contentRect.right -= 15;
  170.     ClipRect(&contentRect);
  171.  
  172. #ifndef PODIUM_APP
  173.     DoDrawGrowIcon(theDocument->theWindow);
  174. #else
  175.     
  176.     // copy the background picture to the offscreen buffer and 
  177.     // composite the geometry image
  178.     {
  179.         CGrafPtr        savedPort ;
  180.         GDHandle        savedGDH ;
  181.         OSErr            theErr ;
  182.         
  183.         GetGWorld( &savedPort, &savedGDH ) ;
  184.         SetGWorld( theDocument->screenBuffer, nil ) ;
  185.     
  186.         // this is the background picture
  187.         CopyBits(&((GrafPtr) theDocument->bgOffscreen)->portBits,
  188.                  &((GrafPtr) theDocument->screenBuffer)->portBits,
  189.                  &theDocument->bgOffscreen->portRect, 
  190.                  &theDocument->bgOffscreen->portRect, 
  191.                  srcCopy, 
  192.                  0L);
  193.     
  194.         // only copy from the offscreen if there is 
  195.         // a valid group in the document
  196.         
  197.         if( theDocument->documentGroup != NULL ) {
  198.             
  199.                          
  200.             CopyBits(&((GrafPtr) theDocument->geometriesOffscreen)->portBits,
  201.                      &((GrafPtr) theDocument->screenBuffer)->portBits,
  202.                      &theDocument->geometriesOffscreen->portRect, 
  203.                      &theDocument->dropArea, 
  204.                      srcCopy | transparent, 
  205.                      0L);
  206.         }
  207.         SetGWorld( (CGrafPtr)theDocument->theWindow, nil ) ;
  208.         
  209.         CopyBits(&((GrafPtr) theDocument->screenBuffer)->portBits,
  210.                  &theDocument->theWindow->portBits,
  211.                  &theDocument->screenBuffer->portRect, 
  212.                  &theDocument->screenBuffer->portRect, 
  213.                  srcCopy, 
  214.                  0L);
  215.         
  216.         
  217.         SetGWorld( savedPort, savedGDH ) ;
  218.     }
  219.  
  220. #endif
  221.     
  222.  
  223.     SetClip(oldClip);
  224.     DisposeRgn(oldClip);
  225.     SetPort( savedPort ) ;
  226. #endif
  227. }
  228.